package com.company.finance.ddd.domain.core.bill.aggregate;

import com.company.finance.ddd.domain.core.bill.enums.BillSubTypeEnum;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static com.company.finance.ddd.domain.core.bill.enums.BillSubTypeEnum.*;

/**
 * 由于不同类型单据对应的明细表不同，为达到在一个位置中统一集中配制单据与明细间对应关系的目的，
 * 从而降低维护难度并提升业务可扩展性，采用约定优于配置原则，将单据明细表的repository(~ItemRepository)
 * 以及与其对应的assembler(~ItemAssembler)的前缀通过单据的billSubType属性进行映射。
 * @author wanglei
 */
public class BillSubTypeMapper {

    private static final Map<BillSubTypeEnum, String> CLASS_PREFIX_NAME_MAP;

    static {
        Map<BillSubTypeEnum, String> classItemPrefix = new HashMap<>();
        classItemPrefix.put(PURCHASE_EXPENSE, "expense");
        classItemPrefix.put(SUPPLIER_EXPENSE, "expense");
        classItemPrefix.put(FINGER, "fingertip");
        classItemPrefix.put(RELATED_TRANSACTION, "purchase");
        classItemPrefix.put(PURCHASE_PAYMENT, "pay");

        CLASS_PREFIX_NAME_MAP = Collections.unmodifiableMap(classItemPrefix);
    }

    public static String getClassPrefixName(BillSubTypeEnum billSubTypeEnum) {
        return CLASS_PREFIX_NAME_MAP.get(billSubTypeEnum);
    }
}
